<!DOCTYPE html>
<html lang="en">
<title>渠道用户列表</title> <#import "/layout/layout.html" as body/>
<@body.page>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<div class="row wrapper border-bottom white-bg page-heading">
	<div class="col-lg-10">
		<h2>运营管理</h2>
		<ol class="breadcrumb">
			<li><a href="#">运营管理</a></li>
			<li class="active"><strong>渠道用户列表</strong></li>
		</ol>
	</div>
</div>
<div class="wrapper wrapper-content animated fadeInRight">
	<div class="row">
		<div class="col-lg-12">
			<div class="ibox float-e-margins">
				<div class="ibox-title overflow">
					<h5 class="pull-left">渠道用户列表</h5>
					<a href="${baseUrl}system/channel/to_channer_and"
						class="btn btn-sm btn-primary pull-right">新增渠道用户</a>
				</div>
				<div class="ibox-content">

					<div class="table-responsive">
						<form class="form-inline" action="to_channer_list" role="form" id="form" method="post" accept-charset="UTF-8">
							<div class="form-group margin-left">
								<label for="channelName">渠道用户名：</label> <input
									class="form-control" name="channelName" id="channelName" type="text"
									placeholder="请输入用户名" value="${channelName!''}" />
							</div>
							<div class="form-group margin-left">
								<label for="mobile">用户手机号：</label> 
								<input class="form-control" id="mobile" name="mobile" value="${mobile!''}" type="text" placeholder="请输入手机号" />
							</div>
							<div class="form-group margin-left">
								<label for="status">状态：</label> <select class="form-control"
									id="status" name="status">
									<option value="">全部</option>
									<option value="0">上线</option>
									<option value="1">下架</option>
									<option value="-1">删除</option>
								</select>
							</div>
							<div class="form-group margin-left">
								<input class="form-control" id="pageNum" type="hidden"   name="pageNum" value="${pageNum!}"/>
							</div>
							<button type="button" class="btn btn-outline btn-primary" style="margin-top: 5px" id="btn_select">确认</button>
						</form>

						<table class="table table-hover table-center dataTables-example">
							<thead>
								<tr>
									<th>渠道ID</th>
									<th>渠道用户</th>
									<th>子渠道用户</th>
									<th>用户手机号</th>
									<th>优惠券</th>
									<th>创建时间</th>
									<th>带量</th>
									<th>每用户返佣</th>
									<th>合计返佣</th>
									<th>状态</th>
									<th>操作</th>
								</tr>
							</thead>
							<tbody>
								<#if channerQrcode??> <#list channerQrcode as channer>
								<tr>
									<td>${channer.id!}</td>
									<td>${channer.channelName!}</td>
									<td>${channer.channelChild!}</td>
									<td>${channer.mobile!}</td>
									<td>${channer.couponId!}</td>
									<td>${channer.createdTime?date}</td>
									<td>${channer.number!}</td>
									<td>${channer.commision!}</td>
									<td>${channer.commision*channer.number}</td>
									<td>
										
										<#if channer.status = 0> 
										    上线
										<#elseif channer.status = 1> 
										  下架
										<#elseif channer.status = -1> 
											删除
										</#if>
									</td>
									<td>
										<!-- <a class="a_img" href="https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=${channer.ticket!}" download="jxylove">
											<button type="button" class="btn btn-default">
												<i class="fa fa-qrcode"></i> 下载二维码
											</button>
										</a> -->
										<button type="button" class="btn btn-default" onclick="downloadImg('${channer.ticket!}','${channer.qrcodeUrl!}','${channer.channelName!}')">
												<i class="fa fa-qrcode"></i> 下载二维码
												<input type="hidden" name="imgs" value="{channer.ticket}">
										</button>
										<a href="channer_edit?id=${channer.id!}">
											<button type="button" class="btn btn-default">
												<i class="fa fa-pencil"></i> 编辑
											</button>
										</a>
										
										<#if channer.status = 0> 
										    <button type="button" class="btn btn-default" onclick="del_channer(${channer.id!})">
												<i class="fa fa-trash-o"></i> 删除
										  	</button>
										<#else> 
										</#if>
									</td>
								</tr>
								</#list> </#if>
							</tbody>
						</table>
					</div>
				</div>
				
				<div class="ibox-content overflow">
					<h4 class="pull-left">合计：#{pageSum!}位渠道用户</h4>
					<div id="copot-page" class="pull-right"></div>
				</div>
			</div>
		</div>
	</div>
</div>
<div style="display: none;" id="testDiv">
	 <div id="qrcode"></div>  
        <a id="download" download="qrcode.jpg"></a>  
        <button id="save">save</button>  
</div>
<script src="${baseUrl}js/main.js"></script>
<script src="${baseUrl}js/channel/jquery.qrcode.min.js"></script>
<!-- <script type='text/javascript' src='http://cdn.staticfile.org/jquery/2.1.1/jquery.min.js'></script>   -->
<!-- <script type="text/javascript" src="http://cdn.staticfile.org/jquery.qrcode/1.0/jquery.qrcode.min.js"></script>  --> 
<script>
    $(document).ready(function () {
        //分页
        new Page({
            parent: $("#copot-page"),
            nowPage: #{pageNum},
            pageSize: 10,
            totalCount: #{pageSum},
            setting: {
                defaultPage: 7,//默认显示可点击分页的个数 Math.floor(#{pageSum}/10)
                firstPageText: "首页",
                prevPageText: "上一页",
                nextPageText: "下一页",
                lastPageText: "尾页"
            },
            callback: function (nowPage, totalPage) {
            	$("#pageNum").val(nowPage);
           	 	$("#form").submit();
            }
        });
        
        
     
                 
    });
  
    $("#btn_select").click(function(){
    	$("#form").submit();
    });
    function del_channer(id){
    	
    	swal({
    		title: '是否删除！',
            text: "点击'确定'进行删除，点击'继续'停留此页刷新当前页",
            type: 'question',
            showCancelButton: true,
            cancelButtonColor: '#d33',
            confirmButtonText: '确定',
            cancelButtonText: '继续'
    		}).then(function () {
    			$.ajax({
    	  	        url: 'channer_del?id='+id,//
    	  	        data: "",
    	  	        type: 'post',
    	  	        cache: false,
    	  	        dataType: 'json',
    	  	        success: function (data) {
    	  	        	if(data.data >0){
    	  	        		
    	  	  	      		$("#form").submit();
    	  	        	}else{
    	  	        		swal({
    	  	  		            title: "删除失败",
    	  	  		            html: "联系管理员",
    	  	  		            type: "error"
    	  	  		        });
    	  	        		return ;
    	  	        	}
    	  	        	
    	  	        },
    	  	        error: function () {
    	  	            swal({
    	  		            title: "删除失败",
    	  		            html: "联系管理员",
    	  		            type: "error"
    	  		        });
    	  	        }
    	  	    });
    		}, function (dismiss) {
    		  if (dismiss === 'cancel') {
    		  }
    		});
    	
  	   
     }
    
    function downloadImg(url,name,fileName){
    	var urls = 'https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket='+url;
    	fileName= fileName+".jpg";
    	$("#testDiv").empty();
    	html = '<div id="qrcode"></div><a id="download" download="qrcode.jpg"></a><button id="save">save</button>';
    	$("#testDiv").append(html);
    	jQuery('#qrcode').qrcode({width: 500,height: 500,text: name});
    	var canvas = $('#qrcode').find("canvas").get(0);  
        var urlnew = canvas.toDataURL(name);  
        $("#download").attr('download',fileName).click(); 
        $("#download").attr('href', "").click(); 
        $("#download").attr('href', urlnew).get(0).click(); 
        $("#testDiv").empty();
        return false;    
    }
</script>
</@body.page>
</html>